package com.wgts.wgts.mvp.view.activity.wgtsteam;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.wgts.wgts.R;
import com.wgts.wgts.base.BaseActivity;
import com.wgts.wgts.dagger.ComponentHolder;
import com.wgts.wgts.dagger.component.DaggerWgtsMyFansActivityComponent;
import com.wgts.wgts.dagger.module.WgtsMyFansActivityModule;
import com.wgts.wgts.mvp.presenter.IWgtsMyFansActivityPresenter;
import com.wgts.wgts.mvp.view.IWgtsMyFansActivityView;
import com.wgts.wgts.netmodle.resp.WgtsFansSummyEntity;

import java.util.List;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class WgtsMyFansActivity extends BaseActivity implements IWgtsMyFansActivityView {
    @BindView(R.id.back_btn_image)
    ImageView backBtnImage;
    @BindView(R.id.back_btn_ly)
    LinearLayout backBtnLy;
    @BindView(R.id.include_title)
    TextView includeTitle;
    @BindView(R.id.include_text)
    TextView includeText;
    @BindView(R.id.include_right_image)
    ImageView includeRightImage;
    @BindView(R.id.include_right_ly)
    LinearLayout includeRightLy;
    @BindView(R.id.img_one)
    ImageView imgOne;
    @BindView(R.id.tv_one_title)
    TextView tvOneTitle;
    @BindView(R.id.img_one_arrow)
    ImageView imgOneArrow;
    @BindView(R.id.linear_one)
    LinearLayout linearOne;
    @BindView(R.id.img_two)
    ImageView imgTwo;
    @BindView(R.id.tv_two_title)
    TextView tvTwoTitle;
    @BindView(R.id.img_two_arrow)
    ImageView imgTwoArrow;
    @BindView(R.id.linear_two)
    LinearLayout linearTwo;
    @BindView(R.id.img_three)
    ImageView imgThree;
    @BindView(R.id.tv_three_title)
    TextView tvThreeTitle;
    @BindView(R.id.img_three_arrow)
    ImageView imgThreeArrow;
    @BindView(R.id.linear_three)
    LinearLayout linearThree;

    @Inject
    IWgtsMyFansActivityPresenter presenter;
    @BindView(R.id.tv_one_people)
    TextView tvOnePeople;
    @BindView(R.id.tv_two_people)
    TextView tvTwoPeople;
    @BindView(R.id.tv_three_people)
    TextView tvThreePeople;

    private String title;

    public static final String TITLE = "TITLE";

    public static final String RELATIONLEVEL = "relationLevel";

    private String relationLevel;

    @Override
    public void init() {
        title = getIntent().getStringExtra(TITLE);
        relationLevel = getIntent().getStringExtra(RELATIONLEVEL);
        DaggerWgtsMyFansActivityComponent
                .builder()
                .appComponent(ComponentHolder.getInstance().getAppComponent())
                .wgtsMyFansActivityModule(new WgtsMyFansActivityModule(this))
                .build()
                .inject(this);
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.wgts_my_fans);
        ButterKnife.bind(this);
        initView();
    }

    private void initView() {
        includeTitle.setText(title);
        presenter.wgtsFansSum(relationLevel);
    }


    @Override
    public void onError(int status, String msg) {

    }

    @Override
    public void initFans(List<WgtsFansSummyEntity> wgtsFansSummyEntities) {
        for (WgtsFansSummyEntity item : wgtsFansSummyEntities) {
            if (item.userRole == 0) {
                tvThreePeople.setText(item.count + "人");
            }
            if (item.userRole == 1) {
                tvTwoPeople.setText(item.count + "人");
            }
            if (item.userRole == 2) {
                tvOnePeople.setText(item.count + "人");
            }
        }
    }

    @OnClick({R.id.linear_one, R.id.linear_two, R.id.linear_three, R.id.back_btn_ly})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.linear_one:
                jump("钻石推手", relationLevel, "2");
                break;
            case R.id.linear_two:
                jump("金牌推手", relationLevel, "1");
                break;
            case R.id.linear_three:
                jump("普通用户", relationLevel, "0");
                break;
            case R.id.back_btn_ly:
                finish();
                break;
        }
    }

    public void jump(String title, String relationLevel, String userRole){
        Intent intent = new Intent(this, WgtsFansListActivity.class);
        intent.putExtra(WgtsFansListActivity.TITLE,  title);
        intent.putExtra(WgtsFansListActivity.RELATION_LEVEL, relationLevel);
        intent.putExtra(WgtsFansListActivity.USER_ROLE, userRole);
        startActivity(intent);
    }
}
